package com.bstek.sample;

import cn.hutool.core.lang.UUID;
import com.bstek.bdf4.dorado.jpa.JpaUtil;
import com.bstek.bdf4.notice.domain.Template;
//import com.bstek.sample.dao.NoticeDao;
import com.bstek.sample.dao.NoticesRepository;
import com.bstek.sample.domain.Notices;
import org.malagu.linq.lin.Lind;
import org.malagu.linq.lin.Linq;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.persistence.EntityManager;
import java.util.Date;
import java.util.List;

/**
 * @Title: SampleService
 * @Package: com.bstek.bdf3.sample.service
 * @Description:
 * @Author: zxq
 * @Date: 2023/11/1 - 12:15
 */

@RestController
@RequestMapping("/api")
public class SampleService {

    @Resource
    NoticesRepository noticesRepository;

    @GetMapping("nn")
    public Object loads(){
        List<Notices> all = noticesRepository.findAll();
        return all;
    }

    @GetMapping("save")
    @Transactional("jpaTransactionManager")
    public Object save(){
        Notices notices = new Notices();
        notices.setId(UUID.fastUUID().toString());
        notices.setContent("1");
        notices.setSendTime(new Date());
        notices.setTitle("2");
        Notices save = noticesRepository.save(notices);
        return save;
    }

//    @Resource
//    private NoticeDao noticeDao;

    @GetMapping("say")
    public Object say(){
        return "say";
    }

    @GetMapping("test")
    public List<Template> load() {
        EntityManager manager = JpaUtil.getEntityManager("jpaEntityManagerFactory");

        EntityManager jpaEntityManagerFactory = JpaUtil.createEntityManager("jpaEntityManagerFactory");
        return org.malagu.linq.JpaUtil.linq(Notices.class, jpaEntityManagerFactory).list();

    }
    @GetMapping("user")
    public Object loadUsers() {
        return JpaUtil.linq(Notices.class)
                .list();
    }

//    @GetMapping("notice")
//    public Object loadNotice() {
//        List<Notice> all = noticeDao.findAll();
//        return all;
//    }

    public static void main(String[] args) {
        System.out.println("11111111");
    }

}
